package com.example.clxy.controller;

import com.alibaba.druid.sql.PagerUtils;
import com.example.clxy.entity.Schedule;
import com.example.clxy.entity.dto.ScheduleDto;
import com.example.clxy.entity.dto.Wrapper;
import com.example.clxy.interceptor.AppToken;
import com.example.clxy.result.Page;
import com.example.clxy.result.PageResult;
import com.example.clxy.result.WebRestResult;
import com.example.clxy.result.business.PageResult.SchedulePageResult;
import com.example.clxy.result.business.PageResult.ScheduleRemindResult;
import com.example.clxy.result.business.PageResult.SemesterPageResult;
import com.example.clxy.result.business.ScheduleResult;
import com.example.clxy.result.business.ScheduleSafetynoticeResult;
import com.example.clxy.result.business.ScheduleSemesterResult;
import com.example.clxy.service.ScheduleService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author liuhaoqi
 * @Date 2020/8/4 21:00
 * @Version 1.0
 */
@AppToken
@RestController
@RequestMapping("ScheduleController")
public class ScheduleController {

    @Autowired
    ScheduleService scheduleService;

//    /**
//     * 新增排课
//     *
//     * @param scheduleWrapper
//     * @return
//     */
//    @CrossOrigin
//    @PostMapping("addScheduleByDataList")
//    public WebRestResult addSchedule(@RequestBody Wrapper<Schedule> scheduleWrapper) {
//        WebRestResult result = scheduleService.addScheduleByDataList(scheduleWrapper);
//        return result;
//    }

    /**
     * 删除排课
     *
     * @param scheduleid
     * @return
     */
    @CrossOrigin
    @PostMapping("deleteSchedule")
    public WebRestResult deleteSchedule(String scheduleid) {
        WebRestResult result = scheduleService.deleteSchedule(scheduleid);
        return result;
    }

    @CrossOrigin
    @PostMapping("updateSchedule")
    public WebRestResult updateSchedule(@RequestBody Schedule schedule) {
        WebRestResult result = scheduleService.updateSchedule(schedule);
        return result;
    }

    /**
     * 学生 老师 按学期查询排课接口
     * 排课状态: status : "0" 表示默认所有  "1"表示未上的排课  “2”表示已上的排课
     *
     * @param userid
     * @param semesterid
     * @param page
     * @param pagesize
     * @param experimentname
     * @param grade
     * @param wlclassname
     * @param wlclassid
     * @return
     */
    @CrossOrigin
    @GetMapping("getScheduleListByUser")
    public PageResult<SchedulePageResult> getScheduleListByUser(String userid, String semesterid, String platformid,
                                                                int page, int pagesize, String experimentname, String grade, String wlclassname, String wlclassid, String status) {
        PageResult<SchedulePageResult> result = scheduleService.getScheduleListByUser(userid, semesterid, platformid, experimentname, wlclassid, wlclassname, grade, page, pagesize, status);
        return result;
    }

    /**
     * 获取周课表
     *
     * @param userid
     * @param weekdate
     * @return
     */
    @CrossOrigin
    @GetMapping("getScheduleListByWeekUser")
    public PageResult<List<SchedulePageResult>> getScheduleListByWeekUser(String userid, String weekdate) {
        PageResult<List<SchedulePageResult>> result = scheduleService.getScheduleListByWeekUser(userid, weekdate);
        return result;
    }

    /**
     * 获取单个排课信息
     *
     * @param scheduleid 排课id
     * @return
     */
    @CrossOrigin
    @GetMapping("getScheduleByid")
    public ScheduleResult getScheduleByid(String scheduleid) {
        ScheduleResult result = scheduleService.getScheduleByid(scheduleid);
        return result;
    }

    /**
     * 新增排课
     *
     * @param scheduleDto
     * @return
     */
    @CrossOrigin
    @PostMapping("addSchedule")
    public WebRestResult addSchedule(@RequestBody ScheduleDto scheduleDto) {
        WebRestResult result = scheduleService.addSchedule(scheduleDto);
        return result;
    }

//    /**
//     * 获取已经排课的学期列表
//     * @param page
//     * @param pagesize
//     * @param semestername
//     * @return
//     */
//    @CrossOrigin
//    @GetMapping("getSemesterListHaveSchedule")
//    public PageResult<SchedulePageResult> getSemesterListHaveSchedule(int page,int pagesize,String semestername) {
//        PageResult<SchedulePageResult> result = scheduleService.getSemesterListHaveSchedule(page,pagesize,semestername);
//        return result;
//    }

//    /**
//     * 获取还未排课的学期列表
//     * @return
//     */
//    @CrossOrigin
//    @GetMapping("getSemesterListNotSchedule")
//    public PageResult<SemesterPageResult> getSemesterListNotSchedule() {
//        PageResult<SemesterPageResult> result = scheduleService.getSemesterListNotSchedule();
//        return result;
//    }

    @CrossOrigin
    @PostMapping("addSemesterProgram")
    public WebRestResult addSemesterProgram(@RequestBody Schedule schedule) {
        WebRestResult result = scheduleService.addSemesterProgram(schedule);
        return result;
    }

    @CrossOrigin
    @PostMapping("deleteSemesterProgram")
    public WebRestResult deleteSemesterProgram(String semesterid, String programid) {
        WebRestResult result = scheduleService.deleteSemesterProgram(semesterid, programid);
        return result;
    }

    @CrossOrigin
    @PostMapping("updateSemesterProgram")
    public WebRestResult updateSemesterProgram(String semesterid, String programid) {
        WebRestResult result = scheduleService.updateSemesterProgram(semesterid, programid);
        return result;
    }

    @CrossOrigin
    @GetMapping("getSemesterProgramList")
    public PageResult<SchedulePageResult> getSemesterProgram(int page, int pagesize, String semestername, String programname) {
        PageResult<SchedulePageResult> result = scheduleService.getSemesterProgram(page, pagesize, semestername, programname);
        return result;
    }

    @CrossOrigin
    @GetMapping("getSemesterNoProgramList")
    public PageResult<SemesterPageResult> getSemesterNoProgramList() {
        PageResult<SemesterPageResult> result = scheduleService.getSemesterNoProgramList();
        return result;
    }

    @CrossOrigin
    @GetMapping("getAllSchedulebySemester")
    public ScheduleSemesterResult getAllSchedulebySemester(String userid, String semesterid) {
        ScheduleSemesterResult result = scheduleService.getAllSchedulebySemester(userid, semesterid);
        return result;
    }

    /**
     * 首页获取明日课表提醒
     *
     * @param userid
     * @return
     */
    @CrossOrigin
    @GetMapping("getScheduleRemindByUser")
    public PageResult<ScheduleRemindResult> getScheduleRemindByUser(String userid) {
        PageResult<ScheduleRemindResult> result = scheduleService.getScheduleRemindByUser(userid);
        return result;
    }

    @CrossOrigin
    @GetMapping("getSafetynoticeByScheduleid")
    public ScheduleSafetynoticeResult getSafetynoticeByScheduleid(String scheduleid) {
        ScheduleSafetynoticeResult result = scheduleService.getSafetynoticeByScheduleid(scheduleid);
        return result;
    }
}
